import req from "/@/api/req";
import {
  ApplyNumItem,
  CancelApplyItem,
  DispatchWorkOrderItem,
  RevokeServiceOrderItem,
  ServiceApplyInfo,
  ServiceFlowNodes,
  ServiceOrderItem,
} from "./models";
import { WorkOrderInfo } from "../serviceWorkOrder/models";

export enum Api {
  // getApplyPage = "api/iopm/serviceOrders/page",
  getApplyPage = "api/iopm/serviceOrders/pageServiceOrders",
  cancelServiceOrder = "api/iopm/serviceOrders/cancelServiceOrder",
  getServiceOrderById = "api/iopm/serviceOrders/getServiceOrderById",
  revokeServiceOrder = "api/iopm/serviceOrders/revokeServiceOrder",
  submitServiceOrder = "api/iopm/serviceOrders/submitServiceOrder",
  summaryServiceOrders = "api/iopm/serviceOrdersSummary/summaryServiceOrders",
  dispatchWorkOrders = "api/iopm/workOrders/dispatchWorkOrders",
  transferWorkOrders = "api/iopm/workOrders/transferWorkOrders",
  getServiceFlowNodes = "api/iopm/serviceFlowNodes/getServiceFlowNodes",
}
// 获取服务申请流程
export function getServiceFlowNodes(data: RevokeServiceOrderItem) {
  return req.post<Array<ServiceFlowNodes>>(
    {
      url: Api.getServiceFlowNodes,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 取消申请单
export function cancelServiceOrder(data: CancelApplyItem) {
  return req.post<boolean>(
    {
      url: Api.cancelServiceOrder,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 创建申请
export function getServiceOrderById(data: RevokeServiceOrderItem) {
  return req.post<ServiceApplyInfo>(
    {
      url: Api.getServiceOrderById,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 创建申请
export function transferWorkOrders(data: ServiceOrderItem) {
  return req.post<WorkOrderInfo>(
    {
      url: Api.transferWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 创建申请
export function submitServiceOrder(data: ServiceOrderItem) {
  return req.post<boolean>(
    {
      url: Api.submitServiceOrder,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
export function summaryServiceOrders() {
  return req.post<ApplyNumItem>(
    {
      url: Api.summaryServiceOrders,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 派单
export function dispatchWorkOrders(data: DispatchWorkOrderItem) {
  return req.post<ApplyNumItem>(
    {
      url: Api.dispatchWorkOrders,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 撤销工单
export function revokeServiceOrder(data: RevokeServiceOrderItem) {
  return req.post<boolean>(
    {
      url: Api.revokeServiceOrder,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
